/*
 * Copyright (C) 2009 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ScheduleNameWizardPanel.java
 * 
 * Created on Jan 18, 2009 at 7:09:02 PM
 */

package org.robcash.apps.messagepopup.view.wizard;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.robcash.apps.messagepopup.view.components.NameEditor;
import org.robcash.commons.swing.wizard.Wizard;
import org.robcash.commons.swing.wizard.impl.BaseWizardPanel;

/**
 *
 * @author Rob
 */
public class ScheduleNameWizardPanel extends BaseWizardPanel<NameEditor>
        implements ChangeListener {

    private NameEditor editor;

    public ScheduleNameWizardPanel(String id) {
        super(id);
        editor = new NameEditor();
        editor.addChangeListener(this);
        setComponent(editor);
    }

    @Override
    public boolean canFinish() {
        return editor.getEditedName() != null &&
                editor.getEditedName().length() > 0;
    }

    @Override
    public boolean canGoForward() {
        return false;
    }

    @Override
    public void aboutToHide(Wizard wizard, boolean saveWork) {
        if ( saveWork ) {
            SubscriptionModel model = (SubscriptionModel) wizard.getModel();
            model.setSubscriptionName(editor.getEditedName());
        }
        super.aboutToHide(wizard, saveWork);
    }

    public void stateChanged(ChangeEvent e) {
        if ( e.getSource().equals(editor) ) {
            fireChangeListenerStateChanged(new ChangeEvent(this));
        }
    }

}
